const controller = require("../controller/dbServe");
const { JWT } = require("../jwt");
const api =require("../lib/file");
const { commentmessage } = require("../lib/sql");
module.exports = (app) => {
  app.use((req, res, next) => {
    //JWT
    if (req.body.new||req.query.data=='default') {
      next();
      return;
    }

    
    const token = req.headers["authorization"]?.split(" ")[1];
    
      
    if (!(token == "null")) {
      const payload = JWT.verify(token);
      if (payload) {
        next();
      } else {
        res.status(401).send({ message: "token过期" });
      }
    } else {
      res.status(402).send({ message: "没有传回的token" });
    }
  });
  //               用户   登录     注册 找回  相关路由

  //新建用户

  app.post("/insertUser", (req, res) => {
    controller.insertUser(req, res);
  });
  //发送验证码
  app.post("/code", (req, res) => {
    controller.sendCode(req, res);
  });

  //登录用户

  app.post("/loginUser", (req, res) => {
    controller.loginUser(req, res);
  });

  //找回账号重新修改密码
  app.patch("/searchUser", (req, res) => {
    controller.searchUser(req, res);
  });


  //获取默认卡片

app.get('/showCard', (req, res) => {
  controller.showCard(req, res);
})

//获取默认卡片的评论
app.get('/showComment',(req,res)=>{
  controller.showComment(req, res);
})


//             发布内容  发布新卡片
app.post('/addCard', api.addcardupload.single("image"), (req, res) => {
  controller.addCard(req, res);
})
//用户喜欢反馈

app.post('/changefeedbacks',(req, res) =>{
  controller.changefeedbacks(req, res)
})

//用户是否喜欢
app.get('/userLike',(req, res) =>{
  controller.userLike(req,res)
})



//用户举报反馈

app.post('/changefeedbacksreport',(req, res)=>{
  controller.changefeedbacksreport(req, res)
})
//用户是否举报
app.get('/userReport',(req, res) =>{
  controller.userReport(req,res)
})

//发布新评论

app.post('/addCommit',(req, res)=>{

controller.addCommit(req, res)

})

//删除卡片

app.post('/deleteCard',(req, res)=>{
  controller.deleteCard(req, res)
})

app.get('/inputSelectCard',(req, res)=>{
  controller.inputSelectCard(req, res)
})

//获取 follow数据
app.get('/selectFollow',(req, res)=>{
  controller.selectFollow(req, res)
})

//关注操作
app.post('/guanzhuT',(req, res)=>{
  controller.guanzhuT(req, res)
})

//取消关注

app.post('/guanzhuF',(req, res)=>{
  controller.guanzhuF(req, res)
})
//获取用户作品数量
app.get('/usercardCount',(req, res)=>{
  controller.usercardCount(req, res)
})

app.post('/userhead',api.userheadupload.single("image"),(req, res)=>{
  controller.userhead(req, res)
})

app.get('/selectuserall',(req, res)=>{
  controller.selectuserall(req, res)
})

app.post('/bgcpicture',api.bgcupload.single("image"),(req, res)=>{
  controller.bgcpicture(req, res)
})

app.post('/updatename',(req, res)=>{

  controller.updatename(req, res)
})

app.post('/updatebio',(req, res)=>{

  controller.updatebio(req, res)
})
app.get('/commentmessage',(req, res)=>{

  controller.commentmessage(req, res)
})

app.post('/deleteemessage',(req, res)=>{

  controller.deleteemessage(req, res)
})

app.delete('/deletecomment',(req, res)=>{
controller.deletecomment(req, res)

})

app.post('/likemessage',(req, res)=>{
  controller.likemessage(req, res)
})

app.post('/deletelikemessage',(req, res)=>{

controller.deletelikemessage(req, res)
  
})

app.post('/fansmessage',(req, res)=>{
  controller.fansmessage(req, res)

})

app.post('/deletefansmessage',(req, res)=>{
  controller.deletefansmessage(req, res)
})

app.post('/systemmessage',(req, res)=>{
  controller.systemmessage(req, res)
})

app.post('/deletesystemmessage',(req, res)=>{
  controller.deletesystemmessage(req, res)
})

app.post('/getforms',(req, res)=>{
controller.getforms(req, res)
  
})

app.post('/changeformvalue',(req, res)=>{
  controller.changeformvalue(req, res)

})

app.post('/deleterowmessage',(req, res)=>{

controller.deleterowmessage(req, res)

})

app.post('/sendsystemmessage',(req, res)=>{
controller.sendsystemmessage(req, res)

})

};

